//
//  AMapLocationHelper.m
//  client
//
//  Created by WangErdong on 2017/8/5.
//
//

#import "AMapLocationHelper.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapLocationKit/AMapLocationKit.h>

@implementation AMapLocationHelper

+ (NSDictionary *)getLocation {

    [AMapServices sharedServices].apiKey =@"66d22faf4a3433b3a7fcd5ffd7d4702b";
    
    AMapLocationManager *locationManager = [[AMapLocationManager alloc] init];
    
    // 带逆地理信息的一次定位（返回坐标和地址信息）
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    //   定位超时时间，最低2s，此处设置为2s
    locationManager.locationTimeout = 30;
    //   逆地理请求超时时间，最低2s，此处设置为2s
    locationManager.reGeocodeTimeout = 30;
    
    [locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        
        if (error) {

            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
        }
        if (location) {
            
            //位置坐标
            CLLocationCoordinate2D coordinate = location.coordinate;
            
            NSDictionary *dict = @{
                                   @"Lon" : [NSString stringWithFormat:@"%f", coordinate.longitude],
                                   @"Lat" : [NSString stringWithFormat:@"%f", coordinate.latitude]
                                   };
            
            NSLog(@"%@", dict);
        }
    }];
    
    return @{};
}

@end
